package scauCmiScaffolding.compiled;

import org.eclipse.jet.JET2Context;
import org.eclipse.jet.JET2Template;
import org.eclipse.jet.JET2Writer;
import org.eclipse.jet.taglib.RuntimeTagElement;
import org.eclipse.jet.taglib.TagInfo;

public class _jet_cmiCalendarTimeEditor implements JET2Template {
    private static final String _jetns_c = "org.eclipse.jet.controlTags"; //$NON-NLS-1$
    private static final String _jetns_java = "org.eclipse.jet.javaTags"; //$NON-NLS-1$

    public _jet_cmiCalendarTimeEditor() {
        super();
    }

    private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
    
    private static final TagInfo _td_c_get_1_9 = new TagInfo("c:get", //$NON-NLS-1$
            1, 9,
            new String[] {
                "select", //$NON-NLS-1$
            },
            new String[] {
                "$packageName", //$NON-NLS-1$
            } );
    private static final TagInfo _td_java_importsLocation_2_1 = new TagInfo("java:importsLocation", //$NON-NLS-1$
            2, 1,
            new String[] {
                "package", //$NON-NLS-1$
            },
            new String[] {
                "org.example", //$NON-NLS-1$
            } );
    private static final TagInfo _td_java_import_11_2 = new TagInfo("java:import", //$NON-NLS-1$
            11, 2,
            new String[] {
            },
            new String[] {
            } );

    public void generate(final JET2Context context, final JET2Writer __out) {
        JET2Writer out = __out;
        out.write("package ");  //$NON-NLS-1$        
        RuntimeTagElement _jettag_c_get_1_9 = context.getTagFactory().createRuntimeTag(_jetns_c, "get", "c:get", _td_c_get_1_9); //$NON-NLS-1$ //$NON-NLS-2$
        _jettag_c_get_1_9.setRuntimeParent(null);
        _jettag_c_get_1_9.setTagInfo(_td_c_get_1_9);
        _jettag_c_get_1_9.doStart(context, out);
        _jettag_c_get_1_9.doEnd();
        out.write(".base.propertyEditor;");  //$NON-NLS-1$        
        out.write(NL);         
        RuntimeTagElement _jettag_java_importsLocation_2_1 = context.getTagFactory().createRuntimeTag(_jetns_java, "importsLocation", "java:importsLocation", _td_java_importsLocation_2_1); //$NON-NLS-1$ //$NON-NLS-2$
        _jettag_java_importsLocation_2_1.setRuntimeParent(null);
        _jettag_java_importsLocation_2_1.setTagInfo(_td_java_importsLocation_2_1);
        _jettag_java_importsLocation_2_1.doStart(context, out);
        _jettag_java_importsLocation_2_1.doEnd();
        out.write(NL);         
        out.write("import java.beans.PropertyEditorSupport;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("import java.text.ParseException;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("import java.text.SimpleDateFormat;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("import java.util.Calendar;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("import java.util.Date;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("import org.springframework.stereotype.Component;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("@");  //$NON-NLS-1$        
        RuntimeTagElement _jettag_java_import_11_2 = context.getTagFactory().createRuntimeTag(_jetns_java, "import", "java:import", _td_java_import_11_2); //$NON-NLS-1$ //$NON-NLS-2$
        _jettag_java_import_11_2.setRuntimeParent(null);
        _jettag_java_import_11_2.setTagInfo(_td_java_import_11_2);
        _jettag_java_import_11_2.doStart(context, out);
        JET2Writer _jettag_java_import_11_2_saved_out = out;
        while (_jettag_java_import_11_2.okToProcessBody()) {
            out = out.newNestedContentWriter();
            out.write("org.springframework.stereotype.Component");  //$NON-NLS-1$        
            _jettag_java_import_11_2.handleBodyContent(out);
        }
        out = _jettag_java_import_11_2_saved_out;
        _jettag_java_import_11_2.doEnd();
        out.write(NL);         
        out.write("public class CmiCalendarTimeEditor extends PropertyEditorSupport {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\tprivate Calendar calendar = Calendar.getInstance();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("\t@Override");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\tpublic void setAsText(String text) throws IllegalArgumentException {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (text.length() > 0) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\ttext = text.replaceAll(\"T\", \" \");");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\ttry {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t\tSimpleDateFormat simpleDateFormat = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t\tDate date = simpleDateFormat.parse(text);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t\tcalendar.setTime(date);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t\tsetValue(calendar);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t} catch (ParseException e) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t\te.printStackTrace();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t} else");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\tsetValue(null);");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("\t@Override");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\tpublic String getAsText() {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tObject o = super.getValue();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\tif (o != null && o instanceof Calendar) {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\tCalendar calendar = (Calendar) o;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\tSimpleDateFormat simpleDateFormat = new SimpleDateFormat(\"yyyy-MM-dd HH:mm\");");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\tString dateString = simpleDateFormat.format(calendar.getTime());");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\tdateString = dateString.replaceAll(\" \", \"T\");");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn dateString;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t} else");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\t\treturn super.getAsText();");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t}");  //$NON-NLS-1$        
        out.write(NL);         
        out.write(NL);         
        out.write("\tpublic Calendar getCalendar() {");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t\treturn this.calendar;");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("\t}\t\t");  //$NON-NLS-1$        
        out.write(NL);         
        out.write("}\t");  //$NON-NLS-1$        
    }
}
